<?php
/**
 * 功能: 系统管理
 * User: 文丹
 * Date: 2018/7/10 0010
 * Time: 10:31
 */

namespace app\admin\controller;
use app\base\controller\Power;
use think\Db;

class System extends Power{
    protected $beforeActionList = [
        'first'=> ['only'=>'strategy,problem,
        partner,common,
        news,head,index,
        guide,waiter,
        profit_rule,plat_intro,
        account,'],

    ];
    protected function first(){
        $result = $this->testing();
    }
    /**
     * 攻略展示页面
     */
    public function strategy(){
        $strategy = Db::name('strategy')->paginate(10);
        $count    = Db::name('strategy')->count();
        $this->assign([
            'strategy'=>$strategy,
            'count'=>$count,
            'empty'=>'<tr class="text-c empty"><td colspan="6">暂无数据</td></tr>'
        ]);
        return $this->fetch('system:strategy-list');

    }

    /**
     * 攻略添加 页面
     */
    public function strategy_add(){
        $id = intval(input('id'));
        if($id){
            $result = Db::name('strategy')->where('id',$id)->find();
            if($result){
                $this->assign('result',$result);
            }
        }
        return $this->fetch('system:strategy-add');
    }
    public function strategy_hold(){
        $title = trim(input('title'));
        $image = trim(input('image'));
        $video = trim(input('video'));

        /*echo "<pre>";
        print_r($data);
        die;*/
        if(empty($title)||empty($image)||empty($video)){
            return json(['msg'=>'请填写完整的信息','ok'=>false]);
        }
        $data = ['title'=>$title,'logo'=>$image,'video'=>$video];
        $result = Db::name('strategy')->insert($data);
        if($result){
            return json(['msg'=>'添加成功','ok'=>true]);
        }else{
            return json(['msg'=>'添加失败','ok'=>false]);
        }
    }

    /**
     * 攻略修改
     * @return \think\response\Json
     */
    public function strategy_edit(){
        $strategy_id = trim(input('strategy_id'));
        $title = trim(input('title'));
        $image = trim(input('image'));
        $video = trim(input('video'));
        $data = ['title'=>$title,'logo'=>$image,'video'=>$video];
        /*echo "<pre>";
        print_r($data);
        die;*/
        if(empty($title)||empty($image)||empty($video)){
            return json(['msg'=>'请填写完整的信息','ok'=>false]);
        }

        $result = Db::name('strategy')->where('id',$strategy_id)->update($data);
        if($result){
            return json(['msg'=>'修改成功','ok'=>true]);
        }else{
            return json(['msg'=>'修改失败','ok'=>false]);
        }
    }
    /**
     * 攻略删除
     */
    public function strategy_del(){
        $id = intval(input('id'));
        if($id<=0){
            return json(['msg'=>'id必须为正整数','ok'=>false]);
        }
        $result = Db::name('strategy')->where('id',$id)->delete();
        if($result){
            return json(['msg'=>'已删除','ok'=>true]);
        }else{
            return json(['msg'=>'删除失败','ok'=>false]);
        }
    }

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

    /**
     * TODO:问题意见反馈
     */
    public function problem(){
        $problem = Db::name('problem')
            ->order('time desc')
            ->paginate(10,false,['query'=>request()->param()])->each(function($item,$key){
            $item['nickname'] = Db::name('user')->where('id',$item['user_id'])->value('nickname');
            return $item;
        });

        $count   = Db::name('problem')->count();
        $this->assign([
            'problem'=>$problem,
            'count'=>$count,
            'empty'=>'<tr class="text-c empty"><td colspan="6">暂无数据</td></tr>'
        ]);
        return view('');
    }
    /**
     * 问题搜索
     */
    public function problem_search(){
        $common   = trim(input('common'));
        $nickname = trim(input('nickname'));
        $opt      = intval(input('opt'));
        $datemin  = trim(input('datemin'));
        $datemax  = trim(input('datemax'));
        if($opt == 1){
            //按反馈时间搜索
            if(empty($datemin)&&empty($datemax)){
                return json(['msg'=>'搜索条件不能为空','ok'=>false]);
            }
            if(!empty($datemin)&& !empty($datemax)){
                $problem = Db::name('problem')
                    ->whereTime('time','>=',$datemin)
                    ->whereTime('time','<=',$datemax)
                    ->paginate(10,false,['query'=>request()->param()])->each(function($item,$key){
                        $item['nickname'] = Db::name('user')->where('id',$item['user_id'])->value('nickname');
                        return $item;
                    });
                /* echo "<pre>";
                 print_r($problem);
                 die;*/
                $count    = Db::name('problem')->whereTime('time','>=',$datemin)->whereTime('time','<=',$datemax)->count();
                if(!empty($problem[0])){
                    $this->assign([
                        'problem'=>$problem,
                        'count'=>$count,
                        'empty'=>'<tr class="text-c va-m empty"><td colspan="7">暂无数据</td></tr>'
                    ]);
                    return $this->fetch('system:problem',['common'=>$common,'opt'=>$opt,'datemin'=>$datemin,'datemax'=>$datemax,'nickname'=>$nickname]);
                }else{
                    return json(['msg'=>'没有符合条件的结果','ok'=>false]);
                }

            }elseif(empty($datemin)&& !empty($datemax)){
                $problem = Db::name('problem')
                    ->whereTime('time','<=',$datemax)
                    ->paginate(10,false,['query'=>request()->param()])->each(function($item,$key){
                        $item['nickname'] = Db::name('user')->where('id',$item['user_id'])->value('nickname');
                        return $item;
                    });
                $count    = Db::name('problem')->whereTime('time','<=',$datemax)->count();
                if(!empty($problem[0])){
                    $this->assign([
                        'problem'=>$problem,
                        'count'=>$count,
                        'empty'=>'<tr class="text-c va-m empty"><td colspan="7">暂无数据</td></tr>'
                    ]);
                    return $this->fetch('system:problem',['common'=>$common,'opt'=>$opt,'datemin'=>$datemin,'datemax'=>$datemax,'nickname'=>$nickname]);
                }else{
                    return json(['msg'=>'没有符合条件的结果','ok'=>false]);
                }
            }elseif(!empty($datemin)&& empty($datemax)){
                $problem = Db::name('problem')
                    ->whereTime('time','>=',$datemin)
                    ->paginate(10,false,['query'=>request()->param()])->each(function($item,$key){
                        $item['nickname'] = Db::name('user')->where('id',$item['user_id'])->value('nickname');
                        return $item;
                    });
                $count    = Db::name('problem')->whereTime('time','>=',$datemin)->count();
                if(!empty($problem[0])){
                    $this->assign([
                        'problem'=>$problem,
                        'count'=>$count,
                        'empty'=>'<tr class="text-c va-m empty"><td colspan="7">暂无数据</td></tr>'
                    ]);
                    return $this->fetch('system:problem',['common'=>$common,'opt'=>$opt,'datemin'=>$datemin,'datemax'=>$datemax,'nickname'=>$nickname]);
                }else{
                    return json(['msg'=>'没有符合条件的结果','ok'=>false]);
                }
            }

        }elseif($opt==2){
            //反馈内容
            if(empty($common)){
                return json(['msg'=>'搜索条件不能为空','ok'=>false]);
            }
            $problem = Db::name('problem')
                ->where('content','like','%'.$common.'%')
                ->whereOr('phone','like','%'.$common.'%')
                ->paginate(10,false,['query'=>request()->param()])->each(function($item,$key){
                    $item['nickname'] = Db::name('user')->where('id',$item['user_id'])->value('nickname');
                    return $item;
                });
            $count    = Db::name('problem')->where('content','like','%'.$common.'%') ->whereOr('phone','like','%'.$common.'%')->count();
            if(!empty($problem[0])){
                $this->assign([
                    'problem'=>$problem,
                    'count'=>$count,
                    'empty'=>'<tr class="text-c va-m empty"><td colspan="7">暂无数据</td></tr>'
                ]);
                return $this->fetch('system:problem',['common'=>$common,'opt'=>$opt,'datemin'=>$datemin,'datemax'=>$datemax,'nickname'=>$nickname]);
            }else{
                return json(['msg'=>'没有符合条件的结果','ok'=>false]);
            }
        }elseif($opt==3) {
            //反馈人
            if (empty($nickname)) {
                return json(['msg' => '搜索条件不能为空', 'ok' => false]);
            }
            $problem = Db::name('problem')
                ->alias('o')
                ->join('user u', 'o.user_id = u.id')
                ->where('u.nickname', 'like', '%' . $nickname . '%')
                ->field('o.*,u.nickname')
                ->paginate(10, false, ['query' => request()->param()]);
            $count = Db::name('problem')
                ->alias('o')
                ->join('user u', 'o.user_id = u.id')
                ->where('u.nickname', 'like', '%' . $nickname . '%')
                ->count();
            if (!empty($problem[0])) {
                $this->assign([
                    'problem' => $problem,
                    'count' => $count,
                    'empty' => '<tr class="text-c va-m empty"><td colspan="7">暂无数据</td></tr>'
                ]);
                return $this->fetch('system:problem', ['common' => $common, 'opt' => $opt, 'datemin' => $datemin, 'datemax' => $datemax]);
            } else {
                return json(['msg' => '没有符合条件的结果', 'ok' => false]);
            }
        }
    }

    /**
     * 反馈内容删除
     */
    public function problem_del(){
        $id = intval(input('id'));
        if($id<=0){
            return json(['msg'=>'id必须为正整数','ok'=>false]);
        }
        $result = Db::name('problem')->where('id',$id)->delete();
        if($result){
            return json(['msg'=>'删除成功','ok'=>true]);
        }else{
            return json(['msg'=>'删除失败','ok'=>false]);
        }
    }

    ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    /**
     * 申请成为合伙人
     */
    public function partner(){
        $id = intval(input('id'));
        if($id){
            $result = Db::name('partner')->where('id',$id)->find();
            $this->assign('result',$result);
        }

        $intro = Db::name('partner')->select();
        $count = Db::name('partner')->count();
        $this->assign([
            'intro'=>$intro,
            'count'=>$count,
            'empty'=>'<tr class="text-c empty"><td colspan="5">暂无数据</td></tr>'
        ]);
        return view('');
    }
    /**
     * 合伙人申请介绍添加
     */
    public function intro_add(){
        $title = trim(input('title'));
        $video = trim(input('video'));
        if(empty($title) || empty($video)){
            return json(['msg'=>'请填写完整的数据','ok'=>false]);
        }
        $data = [
            'title'=>$title,
            'video'=>$video,
            'time'=>time()
        ];
        $result = Db::name('partner')->insert($data);
        if($result){
            return json(['msg'=>'添加成功','ok'=>true]);
        }else{
            return json(['msg'=>'添加失败','ok'=>false]);
        }
    }

    /**
     * 修改保存
     */
    public function intro_edit(){
        $id = trim(input('id'));
        $title = trim(input('title'));
        $video = trim(input('video'));
        if(empty($title) || empty($video)){
            return json(['msg'=>'请填写完整的数据','ok'=>false]);
        }
        $data = [
            'title'=>$title,
            'video'=>$video
        ];
        $result = Db::name('partner')->where('id',$id)->update($data);
        if($result){
            return json(['msg'=>'修改成功','ok'=>true]);
        }else{
            return json(['msg'=>'修改失败','ok'=>false]);
        }
    }

    /**
     * 介绍删除
     */
    public function intro_del(){
        $id = trim(input('id'));
        if($id<=0){
            return json(['msg'=>'id必须为正整数','ok'=>false]);
        }
        $result = Db::name('partner')->where('id',$id)->delete();
        if($result){
            return json(['msg'=>'已删除','ok'=>true]);
        }else{
            return json(['msg'=>'删除失败','ok'=>false]);
        }
    }

    /**
     * 高级合伙人设置
     */
    public function senior(){
        $res = Db::name('senior')->select();
        $this->assign([
            'res'=>$res,
            'empty'=>'<tr class="text-c empty"><td colspan="5">暂无数据</td></tr>'
        ]);
        return view('');
    }
    /**
     * 修改
     */
    public function set_senior(){
        $id = intval(input('id'));
        $culture = trim(input('culture'));
        $bonus = input('bonus')/100;
        $condition = trim(input('condition'));
        if($id<=0){
            return json(['msg'=>'id必须为正整数','ok'=>false]);
        }
        $data = [
            'culture'=>$culture,
            'bonus'=>$bonus,
            'condition'=>$condition
        ];
         $res = Db::name('senior')->where('id',$id)->update($data);
        if($res){
            return json(['msg'=>'已修改','ok'=>true]);
        }else{
            return json(['msg'=>'修改失败','ok'=>false]);
        }
    }

    ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    /**
     * TODO:常见问题
     */
    public function common(){
        $common = Db::name('common')->paginate(10);
        $count = Db::name('common')->count();
        $this->assign([
            'common'=>$common,
            'count'=>$count,
            'empty'=>'<tr class="text-c empty"><td colspan="6">暂无数据</td></tr>'
        ]);
        return view('');
    }

    /**
     * 常见问题添加
     */
    public function common_add(){
        $id = intval(input('id'));
        if($id){
            $result = Db::name('common')->where('id',$id)->find();
            $this->assign('result',$result);
        }
        return $this->fetch('system:common-add');
    }
    /**
     * 验证标题
     */
    public function checkTitle(){
        $title = trim(input('title'));
        $result = Db::name('common')->where('title',$title)->find();
        if($result){
            return json(['msg'=>'该问题已经添加','ok'=>false]);
        }else{
            return json(['msg'=>'正确','ok'=>true]);
        }
    }

    /**
     * 常见问题添加保存
     */
    public function common_hold(){
        $title = trim(input('title'));
        $intro = trim(input('intro'));

        if(empty($title)||empty($intro)){
            return json(['msg'=>'请填写完整的数据','ok'=>false]);
        }
        $check = Db::name('common')->where('title',$title)->find();
        if($check){
            return json(['msg'=>'该标题已经存在','ok'=>false]);
        }
        $data = [
            'title'=>$title,
            'intro'=>$intro,
            'time'=>time()
        ];
        $result = Db::name('common')->insert($data);
        if($result){
            return json(['msg'=>'添加成功','ok'=>true]);
        }else{
            return json(['msg'=>'添加失败','ok'=>false]);
        }
    }

    /**
     * 除本身检测
     */
    public function check_tit(){
        $title = trim(input('title'));
        $id    = intval(input('id'));
        $result = Db::name('common')->where('title',$title)->whereNotIn('id',$id)->find();
        if($result){
            return json(['msg'=>'该问题已经存在','ok'=>false]);
        }else{
            return json(['msg'=>'正确','ok'=>true]);
        }
    }

    /**
     * 常见问题 修改
     */
    public function common_edit(){
        $common_id = intval(input('common_id'));
        $title = trim(input('title'));
        $intro = trim(input('intro'));
        if(empty($title)||empty($intro)){
            return json(['msg'=>'请填写完整的数据','ok'=>false]);
        }
        $check = Db::name('common')->where('title',$title)->whereNotIn('id',$common_id)->find();
        if($check){
            return json(['msg'=>'该标题已经存在','ok'=>false]);
        }
        $data = [
            'title'=>$title,
            'intro'=>$intro
        ];
        $result = Db::name('common')->where('id',$common_id)->update($data);
        if($result){
            return json(['msg'=>'修改成功','ok'=>true]);
        }else{
            return json(['msg'=>'修改失败','ok'=>false]);
        }
    }

    /**
     * 常见问题删除
     */
    public function common_del(){
        $id = trim(input('id'));
        if($id<=0){
            return json(['msg'=>'id必须为正整数','ok'=>false]);
        }
        $result = Db::name('common')->where('id',$id)->delete();
        if($result){
            return json(['msg'=>'已删除','ok'=>true]);
        }else{
            return json(['msg'=>'删除失败','ok'=>false]);
        }
    }

    /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

    /**
     * 系统消息
     */
    public function news(){
        $news = Db::name('news')->paginate(10);
        $count  = Db::name('news')->count();
        $this->assign([
            'news'=>$news,
            'count'=>$count,
            'empty'=>'<tr class="text-c empty"><td colspan="7">暂无数据</td></tr>'
        ]);
        return view('');
    }
    /**
     * 系统消息添加
     */
    public function news_add(){
        return $this->fetch('system:news-add');
    }
    /**
     * 系统消息添加
     */
    public function news_hold(){
        $title   = trim(input('title'));
        $content = trim(input('content'));
        if(empty($title)||empty($content)){
            return json(['msg'=>'请填写完整的数据！','ok'=>false]);
        }
        $data = [
            'title'=>$title,
            'content'=>$content,
        ];
        $result = Db::name('news')->insert($data);
        if($result){
            return json(['msg'=>'添加成功','ok'=>true]);
        }else{
            return json(['msg'=>'添加失败','ok'=>false]);
        }
    }
    /**
     * 消息下架
     */
    public function stop(){
        $id = intval(input('id'));
        if($id<=0){
            return json(['msg'=>'id必须为正整数','ok'=>false]);
        }
        $result = Db::name('news')->where('id',$id)->update(['is_down'=>2]);
        if($result){
            return json(['msg'=>'已下架','ok'=>true]);
        }else{
            return json(['msg'=>'下架失败','ok'=>false]);
        }
    }
    /**
     * 消息发布
     */
    public function start(){
        $id = intval(input('id'));
        if($id<=0){
            return json(['msg'=>'id必须为正整数','ok'=>false]);
        }
        $result = Db::name('news')->where('id',$id)->update(['is_down'=>1,'add_time'=>time()]);
        if($result){
            return json(['msg'=>'已发布','ok'=>true,'add_time'=>date('Y-m-d',time())]);
        }else{
            return json(['msg'=>'发布失败','ok'=>false]);
        }
    }
    /**
     * 消息删除
     */
    public function news_del(){
        $id = intval(input('id'));
        if($id<=0){
            return json(['msg'=>'id必须为正整数','ok'=>false]);
        }
        $result = Db::name('news')->where('id',$id)->delete();
        if($result){
            return json(['msg'=>'已删除','ok'=>true]);
        }else{
            return json(['msg'=>'删除失败','ok'=>false]);
        }
    }


//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    /**
     * 默认头像设置
     */
    public function head(){
        $head  = Db::name('default')->select();
        $count = Db::name('default')->count();
        $this->assign([
            'head'=>$head,
            'count'=>$count,
            'empty'=>'<tr class="text-c empty"><td colspan="6">暂无数据</td></tr>'
        ]);
        return view('');
    }
    /**
     * 默认头像添加
     */
    public function head_add(){
        $id = intval(input('id'));
        if($id){
            $result = Db::name('default')->where('id',$id)->find();
            $this->assign('result',$result);
        }
        return $this->fetch('system:head-add');
    }

    /**
     * 默认头像添加保存
     */
    public function head_hold(){
        $explain = trim(input('explain'));
        $head    = trim(input('head'));
        if(empty($explain)||empty($head)){
            return json(['msg'=>'请填写完整的数据','ok'=>false]);
        }
        $data = [
            'explain'=>$explain,
            'url'=>$head,
        ];
        $result = Db::name('default')->insert($data);
        if($result){
            return json(['msg'=>'添加成功','ok'=>true]);
        }else{
            return json(['msg'=>'添加失败','ok'=>false]);
        }
    }
    /**
     * 默认头像修改
     */
    public function head_save(){
        $id      = intval(input('id'));
        $explain = trim(input('explain'));
        $head    = trim(input('head'));

        /*echo "<pre>";
        print_r($data);
        die;*/
        if(empty($explain)||empty($head)){
            return json(['msg'=>'请填写完整的数据','ok'=>false]);
        }
        $data = [
            'explain'=>$explain,
            'url'=>$head
        ];
        $result = Db::name('default')->where('id',$id)->update($data);
        if($result){
            return json(['msg'=>'修改成功','ok'=>true]);
        }else{
            return json(['msg'=>'修改失败','ok'=>false]);
        }
    }

    /**
     * 默认头像删除
     */
    public function head_del(){
        $id = intval(input('id'));
        if($id<=0){
            return json(['msg'=>'id必须为正整数','ok'=>false]);
        }
        $result = Db::name('default')->where('id',$id)->delete();
        if($result){
            return json(['msg'=>'删除成功','ok'=>true]);
        }else{
            return json(['msg'=>'删除失败','ok'=>false]);
        }
    }

    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

    /**
     * 启动
     */
    public function index(){
        $start = Db::name('start')->select();
        $count = Db::name('start')->count();
        $this->assign([
            'start'=>$start,
            'count'=>$count,
            'empty'=>'<tr class="text-c empty"><td colspan="6">暂无数据</td></tr>'
        ]);
        return view('');

    }

    /**
     * 启动 添加页面
     */
    public function start_add(){
        $id = intval(input('id'));
        if($id){
            $picture = Db::name('start')->where('id',$id)->find();
            $this->assign('picture',$picture);
        }
        return $this->fetch('system:start-add');

    }
    public function start_hold(){
        $a_image = trim(input('android'));
        $ios_image = trim(input('ios'));
        if(empty($a_image)||empty($ios_image)){
            return json(['msg'=>'图片不能为空','ok'=>false]);
        }
        $data = [
            'a_image'=>$a_image,
            'ios_image'=>$ios_image,
            'time'=>time()
        ];
        $result = Db::name('start')->insert($data);
        if($result){
            return json(['msg'=>'添加成功','ok'=>true]);
        }else{
            return json(['msg'=>'添加失败','ok'=>false]);
        }

    }
    /**
     * 启动页图片修改
     */
    public function start_save(){
        $id = trim(input('id'));
        $a_image = trim(input('android'));
        $ios_image = trim(input('ios'));
        if(empty($a_image)||empty($ios_image)){
            return json(['msg'=>'图片不能为空','ok'=>false]);
        }
        $data = [
            'a_image'=>$a_image,
            'ios_image'=>$ios_image,
        ];
        $result = Db::name('start')->where('id',$id)->update($data);
        if($result){
            return json(['msg'=>'修改成功','ok'=>true]);
        }else{
            return json(['msg'=>'修改失败','ok'=>false]);
        }
    }
    //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

    /**
     * 引导页设置
     */
    public function guide(){
        $guide = Db::name('guide')->select();
        $arr = [];
        foreach($guide as $k=>$v){
            $arr[$k] = $v;
            $arr[$k]['android'] = array_filter(explode(',',$v['a_image']));
            $arr[$k]['ios'] = array_filter(explode(',',$v['ios_image']));
        }
        $count = Db::name('guide')->count();
        /*echo "<pre>";
        print_r($arr);
        die;*/
        $this->assign([
            'guide'=>$arr,
            'count'=>$count,
            'empty'=>'<tr class="text-c empty"><td colspan="6">暂无数据</td></tr>'
        ]);
        return view('');
    }
    public function guide_add(){
        $id = intval(input('id'));
        if($id){
            $picture = Db::name('guide')->where('id',$id)->find();
            $picture['android'] = array_filter(explode(',',$picture['a_image']));
            $picture['ios'] = array_filter(explode(',',$picture['ios_image']));

            $this->assign('picture',$picture);
        }
        return $this->fetch('system:guide-add');
    }
    /**
     * 添加引导页
     */
    public function guide_hold(){
        $a_image = trim(input('android'));
        $ios_image = trim(input('ios'));
        if(empty($a_image)||empty($ios_image)){
            return json(['msg'=>'图片不能为空','ok'=>false]);
        }
        $data = [
            'a_image'=>$a_image,
            'ios_image'=>$ios_image,
            'time'=>time()
        ];
        $result = Db::name('guide')->insert($data);
        if($result){
            return json(['msg'=>'添加成功','ok'=>true]);
        }else{
            return json(['msg'=>'添加失败','ok'=>false]);
        }
    }

    /**
     * 修改保存
     */
    public function guide_save(){
        $id = intval(input('id'));
        $a_image = trim(input('android'));
        $ios_image = trim(input('ios'));
        if(empty($a_image)||empty($ios_image)){
            return json(['msg'=>'图片不能为空','ok'=>false]);
        }
        $data = [
            'a_image'=>$a_image,
            'ios_image'=>$ios_image
        ];
        $result = Db::name('guide')->where('id',$id)->update($data);
        if($result){
            return json(['msg'=>'修改成功','ok'=>true]);
        }else{
            return json(['msg'=>'修改失败','ok'=>false]);
        }
    }
    public function guide_del(){
        $id = intval(input('id'));
        $result = Db::name('guide')->where('id',$id)->delete();
        if($result){
            return json(['msg'=>'已成功','ok'=>true]);
        }else{
            return json(['msg'=>'删除失败','ok'=>false]);
        }

    }
    /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    /**
     * 微信客服
     */
    public function waiter(){
        $waiter = Db::name('waiter')->select();
        $count    = Db::name('waiter')->count();
        $this->assign([
            'waiter'=>$waiter,
            'count'=>$count,
            'empty'=>'<tr class="text-c empty"><td colspan="6">暂无数据</td></tr>'
        ]);
        return $this->fetch('system:waiter-list');

    }

    public function waiter_add(){
        $id = intval(input('id'));
        if($id){
            $result = Db::name('waiter')->where('id',$id)->find();
            if($result){
                $this->assign('result',$result);
            }
        }
        return $this->fetch('system:waiter-add');
    }

    public function waiter_hold(){
        $code = trim(input('code'));
        $number = trim(input('number'));
        $date = trim(input('date'));
        if(empty($code)||empty($number)||empty($date)){
            return json(['msg'=>'请填写完整的数据','ok'=>false]);
        }
        $data = [
            'code'=>$code,
            'number'=>$number,
            'date'=>$date,
        ];
        $result = Db::name('waiter')->insert($data);
        if($result){
            return json(['msg'=>'添加成功','ok'=>true]);
        }else{
            return json(['msg'=>'添加失败','ok'=>false]);
        }
    }
    public function waiter_edit(){
        $id = trim(input('waiter_id'));
        $code = trim(input('code'));
        $number = trim(input('number'));
        $date = trim(input('date'));
        if(empty($code)||empty($number)||empty($date)){
            return json(['msg'=>'请填写完整的数据','ok'=>false]);
        }
        $data = [
            'code'=>$code,
            'number'=>$number,
            'date'=>$date,
        ];
        $result = Db::name('waiter')->where('id',$id)->update($data);
        if($result){
            return json(['msg'=>'修改成功','ok'=>true]);
        }else{
            return json(['msg'=>'修改失败','ok'=>false]);
        }
    }
    /**
     * 删除
     */
    public function waiter_del(){
        $id = intval(input('id'));
        $result = Db::name('waiter')->where('id',$id)->delete();
        if($result){
            return json(['msg'=>'已成功','ok'=>true]);
        }else{
            return json(['msg'=>'删除失败','ok'=>false]);
        }
    }


    //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

    /**
     * 收益规则 说明
     */
    public function profit_rule(){
        $result = Db::name('profit_rule')->find();
        if($result){
            $this->assign('result',$result);
        }
        return $this->fetch('profit-rule');
    }
    /**
     * 添加
     */
    public function content_add(){
        $content = input('content');

         if(empty($content)){
             return json(['msg'=>'添加内容不能为空','ok'=>false]);
         }
        $res = Db::name('profit_rule')->insert(['content'=>$content]);
        if($res){
            return json(['msg'=>'添加成功','ok'=>true]);
        }else{
            return json(['msg'=>'添加失败','ok'=>false]);
        }

    }
    /**
     * 修改
     */
    public function content_edit(){
        $content = input('content');
        $rule_id = intval(input('rule_id'));
        if(empty($content)){
            return json(['msg'=>'添加内容不能为空','ok'=>false]);
        }
        $res = Db::name('profit_rule')->where('id',$rule_id)->update(['content'=>$content]);
        if($res){
            return json(['msg'=>'修改成功','ok'=>true]);
        }else{
            return json(['msg'=>'修改失败','ok'=>false]);
        }
    }
    ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
     /*
      * 平台介绍
      */
    public function plat_intro(){
        $result = Db::name('plat_intro')->find();
        if($result){
            $this->assign('result',$result);
        }
        return $this->fetch('plat-intro');
    }
    public function plat_intro_add(){
        $content = input('content');

        if(empty($content)){
            return json(['msg'=>'添加内容不能为空','ok'=>false]);
        }
        $res = Db::name('plat_intro')->insert(['content'=>$content]);
        if($res){
            return json(['msg'=>'添加成功','ok'=>true]);
        }else{
            return json(['msg'=>'添加失败','ok'=>false]);
        }
    }
    public function plat_intro_edit(){
        $content = input('content');
        $rule_id = intval(input('rule_id'));
        if(empty($content)){
            return json(['msg'=>'添加内容不能为空','ok'=>false]);
        }
        $res = Db::name('plat_intro')->where('id',$rule_id)->update(['content'=>$content]);
        if($res){
            return json(['msg'=>'修改成功','ok'=>true]);
        }else{
            return json(['msg'=>'修改失败','ok'=>false]);
        }
    }
    //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    /**
     * 账户问题
     */
    public function account(){
        $result = Db::name('account')->find();
        if($result){
            $this->assign('result',$result);
        }
        return $this->fetch('account');
    }
    public function account_add(){
        $content = input('content');
        if(empty($content)){
            return json(['msg'=>'添加内容不能为空','ok'=>false]);
        }
        $res = Db::name('account')->insert(['content'=>$content]);
        if($res){
            return json(['msg'=>'添加成功','ok'=>true]);
        }else{
            return json(['msg'=>'添加失败','ok'=>false]);
        }
    }
    public function account_edit(){
        $content = input('content');
        $rule_id = intval(input('rule_id'));
        if(empty($content)){
            return json(['msg'=>'添加内容不能为空','ok'=>false]);
        }
        $res = Db::name('account')->where('id',$rule_id)->update(['content'=>$content]);
        if($res){
            return json(['msg'=>'修改成功','ok'=>true]);
        }else{
            return json(['msg'=>'修改失败','ok'=>false]);
        }
    }

    /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////



}

